<?php
require_once('./includes/headers.inc.php');
require_once('./top.php');

$error = FALSE;
$query = '';
$search_result = array();

if($_POST) {
    $query = $_POST['query'];
    if(strlen($query) >= 3) {
        $result = $userMgr->search($_SESSION['user']['id'], $query);
        $search_result[] = '<ul>';
        foreach($result as $row) {
            $search_result[] = '<li><a href="/viewuser.php?id=' . $row['id'] . '">' . $row['name'] . '</a>';
        }
        $search_result[] = '</ul>';
    } else {
        $error = $msgMgr->get('search-short-error');
    }
}

$replaces = array(
    'query'             => $query,
    'search_result'     => implode("\n", $search_result),
    'error'             => $msgMgr->formatMsg($error),
);
$lang = array(
    'header_findfriends' => $langMgr->get('header_findfriends'),
    'btn_search'        => $langMgr->get('btn_search'),
);
$templateMgr->loadContent(basename(__FILE__, '.php'), array_merge($replaces, $lang));
?>
